package com.zhangj.alljvm.reference;

import org.junit.jupiter.api.Test;

import java.lang.ref.WeakReference;

/**
 * @ClassName ReferenceTest02
 * @Description
 * @Author zhangjie
 * @Date 2022/3/11 15:04
 * @Version 1.0
 */
public class ReferenceTest02 {

    @Test
    void weakTest(){
        Object object1 = new Object();
        WeakReference weakReference = new WeakReference(object1);
        System.out.println("object1 = " + object1);
        System.out.println("weakReference.get() = " + weakReference.get());

        object1 = null;
        System.gc();
        System.out.println("==================");
        System.out.println("object1 = " + object1);
        System.out.println("weakReference.get() = " + weakReference.get());

    }

}
